//
//  GWOriginalStatuseFrame.m
//  新浪微博
//
//  Created by qianfeng on 16/2/18.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWOriginalStatuseFrame.h"
#import "GWStatuseModel.h"
#import "GWStatusePhotosView.h"
@implementation GWOriginalStatuseFrame
-(void)setStatuse:(GWStatuseModel *)statuse
{
    _statuse =statuse;
    
    /**头像*/
    CGFloat iconX =HomeStatuseCellInset;
    CGFloat iconY =HomeStatuseCellInset;
    CGFloat iconW =35;
    CGFloat iconH =35;
    self.iconViewF =CGRectMake(iconX, iconY, iconW, iconH);
    /**昵称*/
    CGFloat nameX =CGRectGetMaxX(self.iconViewF)+HomeStatuseCellInset;
    CGFloat nameY =HomeStatuseCellInset;
    CGSize nameSize =[statuse.user.name boundingRectWithSize:CGSizeMake(300, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:OriginalStatuseNameFont} context:nil].size;
    self.nameLabelF =(CGRect){{nameX,nameY},nameSize};
    
    if (statuse.user.isVip) {
        /**vip*/
        CGFloat vipX =CGRectGetMaxX(self.nameLabelF)+HomeStatuseCellInset*0.5;
        CGFloat vipY =nameY;
        CGFloat vipW =nameSize.height;
        CGFloat vipH =nameSize.height;
        self.vipViewF =CGRectMake(vipX, vipY, vipW, vipH);
    }
    /**时间*/
    CGFloat timeX =nameX;
    CGFloat timeY =CGRectGetMaxY(self.nameLabelF)+HomeStatuseCellInset*0.5;
    CGSize timeSize =[statuse.created_at boundingRectWithSize:CGSizeMake(300, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:OriginalStatuseTimeFont} context:nil].size;
    self.timeLabelF =(CGRect){{timeX,timeY},timeSize};
    
    /**来源*/
    CGFloat sourceX =CGRectGetMaxX(self.timeLabelF)+HomeStatuseCellInset;
    CGFloat sourceY =timeY;
    CGSize sourceSize =[statuse.source boundingRectWithSize:CGSizeMake(300, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:OriginalStatuseSourceFont} context:nil].size;
    self.sourceLabelF =(CGRect){{sourceX,sourceY},sourceSize};
   
    
    /**正文*/
    CGFloat textX =HomeStatuseCellInset;
    CGFloat textY =CGRectGetMaxY(self.iconViewF)+HomeStatuseCellInset;
   CGSize textSize = [statuse.attributedText boundingRectWithSize:CGSizeMake(GWScreenW-2*textX, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
//    CGSize textSize =[statuse.text boundingRectWithSize:CGSizeMake(GWScreenW-2*textX, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:OriginalStatuseTextFont} context:nil].size;
    self.textLabelF =(CGRect){{textX,textY},textSize};
    
    CGFloat h =0;
    if (statuse.pic_urls.count) {
        CGFloat photoX =HomeStatuseCellInset;
        CGFloat photoY =CGRectGetMaxY(self.textLabelF)+HomeStatuseCellInset;
        
        CGSize photosSize =[GWStatusePhotosView photosViewSizeWithPhotoCount:(int)statuse.pic_urls.count];
        self.photosViewF =(CGRect){{photoX,photoY},photosSize};
        h=CGRectGetMaxY(self.photosViewF)+HomeStatuseCellInset;
    }
    else
    {
        h=CGRectGetMaxY(self.textLabelF)+HomeStatuseCellInset;
    }
    self.frame =CGRectMake(0, 0, GWScreenW, h);
}
@end
